package class04;

import java.util.Arrays;
import java.util.Comparator;

//给定一组字符串，可以任何调整拼接顺序使得最后结果字典序最小
public class Code04_LowestLexicography {


    public static String lowestString2(String[] strs) {
        if (strs == null || strs.length == 0) {
            return "";
        }
        Arrays.sort(strs, new MyComparator());
        String res = "";
        for (int i = 0; i < strs.length; i++) {
            res += strs[i];
        }
        return res;
    }
    public static class MyComparator implements Comparator<String> {
        @Override
        public int compare(String a, String b) {
            return (a + b).compareTo(b + a);
        }
    }

    public static void main(String[] args) {
        String[] str={"b","ba"};
        System.out.println(lowestString2(str));
    }
}
